package com.recursivechaos.gamemaster.dao;

import com.recursivechaos.gamemaster.classes.GameSettings;

public class GameSettingsDAO extends DAO {

	/**
	 * Returns an integer setting from the settings. Automatically parses the
	 * setting to an integer
	 * 
	 * @param strSetting
	 *            setting name
	 * @return integer value of setting
	 */
	public int getIntSetting(String strSetting) {
		int soughtVal = 0;
		try {
			begin();
			GameSettings settings = (GameSettings) getSession().get(
					GameSettings.class, strSetting);
			commit();
			soughtVal = Integer.parseInt(settings.getValue());
		} catch (Exception e) {
			rollback();
		} finally {
			close();
		}
		return soughtVal;
	}

	/**
	 * Returns a string setting from the settings. This would be the safest
	 * method, because they are all stored as strings.
	 * 
	 * @param strSetting
	 *            setting name
	 * @return integer value of setting
	 */
	public String getStringSetting(String strSetting) {
		String soughtVal = "";
		try {
			begin();
			GameSettings settings = (GameSettings) getSession().get(
					GameSettings.class, strSetting);
			commit();
			soughtVal = settings.getValue();
		} catch (Exception e) {
			rollback();
		} finally {
			close();
		}
		return soughtVal;
	}
}
